<template>
	<view class="container">
		<view class="search">
			<u-search @search="search" @custom="search" :animation="true" placeholder="请输入搜索关键词"
				v-model="keyword"></u-search>
		</view>
		<view class="" style="height: 100%; width: 100%;">
			<view class="" style="padding: 30rpx;" v-if="!goodsShow">
				<view class="items">
					<view class="good" @tap="goDetail(good)" v-for="(good,index2) in goods" :key="index2">
						<image class="image" :src="good.image_url" mode=""></image>
						<view class="right">
							<text class="name">{{ good.name }}</text>
							<text class="tips">{{ good.description }}</text>
							<view class="price_and_action">
								<text class="price">￥{{ ((good.cups[0].price )/100)}}</text>
							</view>
						</view>
					</view>
				</view>
			</view>
			<view class="empty" v-else>
				<image src="../../static/images/empty.png" style="width: 400rpx;" mode="widthFix"></image>
				<view class="" style="color: #b3b5b9;">
					更多新品正在研发中~
				</view>
			</view>
		</view>

	</view>
</template>

<script>
	import {mapState} from 'vuex'
	export default {
		data() {
			return {
				keyword: '',
				goods: [],
				num: 1,
				goodsShow: false
			};
		},
		watch: {
			// keyword(n, o) {
			// 	if (n.length <= 0) {
			// 		this.goodsShow = false
			// 	}
			// }
		},
		onLoad() {

		},
		computed:{
			...mapState(['store'])
		},
		methods: {
			goDetail(e) {
				uni.setStorageSync("goodId", e.id)
				uni.navigateBack()
			},
			async search() {
				if (this.keyword.trim() == '') {
					this.msg('请输入关键词')
					return
				}
				let res = await this.apiPost('/product/productList', {
					keyword: this.keyword,
					shop_id:this.store.id
				})
				console.log(res);
				this.num++
				if (res.data.code == 1) {
					this.goods = res.data.data
					console.log(res.data.data.length, 999);
					if (res.data.data.length == 0) {
						this.goodsShow = true
					} else {
						this.goodsShow = false
					}
				} else {
					this.msg(res.data.msg)
				}


			},
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #fff;
	}

	.container {
		position: relative;

		.search {
			position: sticky;
			top: -6rpx;
			padding: 30rpx;
			height: 120rpx;
			background-color: #fff;
		}

		.empty {
			height: 50vh;
			display: flex;
			flex-direction: column;
			align-items: center;
			justify-content: center;
		}
	}

	.items {
		display: flex;
		flex-direction: column;
		padding-bottom: -30rpx;
		min-height: 200rpx;

		.good {
			display: flex;
			align-items: center;
			margin-bottom: 30rpx;

			.image {
				width: 160rpx;
				height: 160rpx;
				margin-right: 20rpx;
				border-radius: 8rpx;
			}

			.right {
				flex: 1;
				height: 160rpx;
				overflow: hidden;
				display: flex;
				flex-direction: column;
				align-items: flex-start;
				justify-content: space-between;
				padding-right: 14rpx;

				.name {
					font-size: $font-size-base;
					margin-bottom: 10rpx;
				}

				.tips {
					width: 100%;
					height: 40rpx;
					line-height: 40rpx;
					overflow: hidden;
					text-overflow: ellipsis;
					white-space: nowrap;
					font-size: $font-size-sm;
					color: $text-color-assist;
					margin-bottom: 10rpx;
				}

				.price_and_action {
					width: 100%;
					display: flex;
					justify-content: space-between;
					align-items: center;

					.price {
						font-size: $font-size-base;
						font-weight: 600;
					}
				}
			}
		}
	}
</style>